import sys
from copy_files import system_copy_files
from readcfg import get_config

cfgfile = "./datasync.toml"
config = get_config(cfgfile)

homedir = config.homedir
list_strs = config.listed_dirs
syncstr = config.syncdir

syncdir = homedir + syncstr
listed_dirs = [homedir + i for i in list_strs]
tar_dirs = [syncdir + i for i in list_strs]

print("home: " + homedir)
print("sync: " + syncdir)


if len(sys.argv) == 1:
    print("welcome to datasync!")
elif len(sys.argv) == 2:
    if sys.argv[1] == "push":
        print("pushing.")
        system_copy_files(listed_dirs, tar_dirs)
    elif sys.argv[1] == "pull":
        print("pulling.")
        system_copy_files(tar_dirs, listed_dirs)
    else:
        print("unknown argument: " + sys.argv[1])
else:
    print("wrong argument number.")
